package com.jeesite.modules.dataScreen.utils;

import cn.hutool.core.util.NumberUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author: zhaosenlin
 * @date: 2024/7/2 13:55
 */
public class ComputeUtil {

    public static final BigDecimal MULTIPLICAND = new BigDecimal("100");

    public static BigDecimal div(String v1, String v2) {
        BigDecimal b1 = NumberUtil.toBigDecimal(v1);
        BigDecimal b2 = NumberUtil.toBigDecimal(v2);
        if (BigDecimal.ZERO.compareTo(b2) == 0) {
            return BigDecimal.ZERO;
        }
        return NumberUtil.div(b1, b2, 4, RoundingMode.HALF_UP).multiply(MULTIPLICAND);
    }

    public static String divToStr(String v1, String v2) {
        return NumberUtil.toStr(div(v1, v2));
    }
}
